/*
 * Event_StubImpl.java
 *
 * Created on November 5, 2006, 5:39 PM
 */

package tools;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @author mmixon
 */
public class Event_StubImpl extends Object implements Event {
    
    private int id;
    private String title;
    private String startDate;
    private String endDate;
    private String startTime;
    private String endTime;
    private String description;
    private String testdate1 = "12/01/2006";
    private String testdate2 = "12/05/2006";
    private String testdate3 = "12/16/2006";
    private Date td1 = new Date();
    private Date td2 = new Date();
    private Date td3 = new Date();
    private int classId;
    private int locationId;
    private int groupId;
    private int creatorId;
    public ArrayList eventList;
    private String warningMessage;
    private EventItem event;
    public EventItem tempEvent;
    private String statusMsg;
    
    
    public Event_StubImpl() {
        id = 0;
        title = "";
        setStartDate(null);
        setEndDate(null);
        setStartTime("");
        setEndTime("");
        description = "";
        classId = 0;
        locationId = 0;
        groupId = 0;
        creatorId = 0;
        try{
            td1 = convertDate(testdate1);
        } catch(WrongFormatException wfe){
        }
        try{
            td2 = convertDate(testdate2);
        } catch(WrongFormatException wfe){
        }
        try{
            td3 = convertDate(testdate3);
        } catch(WrongFormatException wfe){
        }
        setStatusMsg("");
        setWarningMessage("");
        event = new EventItem();
        tempEvent = new EventItem();
        eventList = new ArrayList();
        eventList.add(new EventItem(1, "Autism 101",td1,
                td1, "5:00pm", "7:00pm",
                "Program for those Learning about Autism", 0, 0, 1, 1));
        eventList.add(new EventItem(2, "Living With Autism", td2,
                td2, "5:00pm", "7:00pm",
                "Program for those living with Autism", 0, 0, 1, 1));
        eventList.add(new EventItem(3, "Parents of the autistic", td3,
                td3, "5:00pm", "7:00pm",
                "Program for those parents", 0, 0, 1, 1));
    }
    
    public void addEvent() {
        event.id = id;
        event.classId = classId;
        event.description = description;
        try{
            event.endDate = convertDate(endDate);
        } catch(WrongFormatException wfe){
        }
        try{
            event.startDate = convertDate(startDate);
        } catch(WrongFormatException wfe){
        }
        
        event.groupId = groupId;
        event.locationId = locationId;
        event.startTime = startTime;
        event.endTime = endTime;
        event.title = title;
        event.creatorId = creatorId;
        eventList.add(event);
        warningMessage = "Event added successfully";
    }
    
    /**
     *
     * @param id
     */
    public void removeEvent(int id) {
    }
    
    /**
     *
     * @param searchString
     */
    public void searchEvent(String searchString) {
    }
    
    /**
     *
     * @return
     */
    public int getId() {
        return id;
    }
    
    /**
     *
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }
    
    /**
     *
     * @return
     */
    public String getTitle() {
        return title;
    }
    
    /**
     *
     * @param title
     */
    public void setTitle(String title) {
        this.title = title;
    }
    
    /**
     *
     * @return
     */
    public String getStartDate() {
        return startDate;
    }
    
    /**
     *
     * @param startDate
     */
    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }
    
    /**
     *
     * @return
     */
    public String getEndDate() {
        return endDate;
    }
    
    /**
     *
     * @param endDate
     */
    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }
    
    /**
     *
     * @param startTime
     */
    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }
    
    /**
     *
     * @return
     */
    public String getStartTime(){
        return startTime;
    }
    
    /**
     *
     * @param endTime
     */
    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }
    
    /**
     *
     * @return
     */
    public String getEndTime(){
        return endTime;
    }
    
    /**
     *
     * @return
     */
    public String getDescription() {
        return description;
    }
    
    /**
     *
     * @param description
     */
    public void setDescription(String description) {
        this.description = description;
    }
    
    /**
     *
     * @return
     */
    public int getClassId() {
        return classId;
    }
    
    /**
     *
     * @param classId
     */
    public void setClassId(int classId) {
        this.classId = classId;
    }
    
    /**
     *
     * @return
     */
    public int getLocationId() {
        return locationId;
    }
    
    /**
     *
     * @param locationId
     */
    public void setLocationId(int locationId) {
        this.locationId = locationId;
    }
    
    /**
     *
     * @return
     */
    public int getGroupId() {
        return groupId;
    }
    
    /**
     *
     * @param groupId
     */
    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }
    
    /**
     *
     * @return
     */
    public int getCreatorId() {
        return creatorId;
    }
    
    /**
     *
     * @param creatorId
     */
    public void setCreatorId(int creatorId) {
        this.creatorId = creatorId;
    }
    
    /**
     *
     * @return
     */
    public String getWarningMessage() {
        return warningMessage;
    }
    
    /**
     *
     * @param warningMessage
     */
    public void setWarningMessage(String warningMessage) {
        this.warningMessage = warningMessage;
        
    }
    
    /**
     *
     * @param dateTime
     * @throws tools.WrongFormatException
     * @return
     */
    public Date convertDate(String dateTime) throws WrongFormatException {
        Date date = new Date();
        DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        try {
            date = (java.util.Date)formatter.parse(dateTime);
        } catch (ParseException e) {
            warningMessage = "Wrong format for date.";
            throw new WrongFormatException(warningMessage);
        }
        
        SimpleDateFormat xdf = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date dDate = java.sql.Date.valueOf(xdf.format(date));
        return dDate;
    }
    
    /**
     *
     * @param date
     * @throws tools.WrongFormatException
     * @return
     */
    public Date convertGregorianDate(Date date) throws WrongFormatException{
        Date newDate = new Date();
        DateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy");
        try{
            newDate = (java.util.Date)formatter.parse(date.toString());
        } catch(ParseException e){
            warningMessage = "Wrong format for date.";
            throw new WrongFormatException(warningMessage);
        }
        
        SimpleDateFormat xdf = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date dDate = java.sql.Date.valueOf(xdf.format(newDate));
        return dDate;
    }
    
    /**
     *
     * @return
     */
    public String getStatusMsg() {
        return statusMsg;
    }
    
    /**
     *
     * @param statusMsg
     */
    public void setStatusMsg(String statusMsg) {
        this.statusMsg = statusMsg;
    }
    
    //gets the size of the event list
    public int eventListSize() {
        if(eventList.isEmpty())
            return 0;
        else
            return eventList.size();
    }
    
    //used by iterator to reference object in
    //eventList
    public void setTempEvent(int iterator){
        tempEvent = (EventItem)eventList.get(iterator);
    }
    
    public class EventItem{
        public int id;
        public String title;
        public Date startDate;
        public Date endDate;
        public String startTime;
        public String endTime;
        public String description;
        public int classId;
        public int locationId;
        public int groupId;
        public int creatorId;
        public EventItem(){
            //constructor
        }
        public EventItem(int id, String title, Date startDate, Date endDate,
                String startTime, String endTime,
                String description, int classId, int locationId, int groupId, int creatorId){
            
            this.id = id;
            this.title = title;
            this.startDate = startDate;
            this.endDate = endDate;
            this.startTime = startTime;
            this.endTime = endTime;
            this.description = description;
            this.classId = classId;
            this.locationId = locationId;
            this.creatorId = creatorId;
        }
        
    }
    
    
}
